package com.cloud.system.api.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Lang;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultType;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

import com.cloud.system.api.entity.RoleInfo;
import com.cloud.system.common.driver.SimpleInlangDriver;
import com.cloud.system.common.utils.BaseMapperHelper;

public interface RoleInfoMapper extends BaseMapperHelper<RoleInfo> {

	@Select("select unit_id from role_info where unit_id in (#{unitIds}) group by unit_id having count(1) > 0")
	@Lang(SimpleInlangDriver.class)
	@ResultType(value = Long.class)
	List<Long> selectUnitRoleCount(@Param("unitIds") List<Long> uids);
	
	
	@Select("select i.role_id, role_name, role_avatar, unit_id, unit_name, unit_code from role_info i where delete_flag = 0 "
			+ "and exists (select role_id from human_role h where i.role_id = h.role_id and human_id = #{humanId})")
	@Results({ @Result(property = "roleId", column = "role_id", javaType = Long.class),
			@Result(property = "roleName", column = "role_name", javaType = String.class),
			@Result(property = "roleAvatar", column = "role_avatar", javaType = String.class),
			@Result(property = "unitId", column = "unit_id", javaType = Long.class), 
			@Result(property = "unitName", column = "unit_name", javaType = String.class),
			@Result(property = "unitCode", column = "unit_code", javaType = String.class)})
	List<RoleInfo> selectHumanRoleByHuman(@Param("humanId") Long humanId);

	@Select("select role_id from human_role where human_id = #{humanId}")
	@ResultType(Long.class)
	List<Long> loafRoleIds(@Param("humanId") Long humanId);
	
}